home *** CD-ROM | disk | FTP | other *** search
- Path: alterdial.uu.net!not-for-mail
- From: rogerst@approach.com (Tom Rogers)
- Newsgroups: comp.lang.c
- Subject: Re: String Arrays and string parsing
- Date: Tue, 20 Feb 1996 20:31:07 GMT
- Message-ID: <4gd0ik$6bs@alterdial.UU.NET>
- References: <31287278.789445@news.inforamp.net> <4gaqrj$3kn@hacgate2.hac.com>
- NNTP-Posting-Host: 198.177.211.32
- X-Newsreader: Forte Free Agent 1.0.82
-
- collins@thor.tu.hac.com (Ron Collins) wrote:
-
-
- >You've almost got it with the "strncpy()". Try this:
- >(assuming you define "from1" somewhere)
-
- >#include <string.h>
-
- >....
-
- >char into1[3];
- >char into2[4];
- >char into3[5];
-
- >...
-
- > strncpy(into1,from1,2);
- > into1[2] = 0;
- > strncpy(into2,from1+2,3);
- > into2[3] = 0;
- > strncpy(into3,from1+5,4);
- > into3[4] = 0;
-
- Ron, for clarities sake, you really ought to terminate your strings
- with '\0' chars rather than 0's. A nit, I know, since they are the
- same, but it is much easier for beginners and maintainers to
- see that you are null terminating a string....
-
- Regards,
- Tom
-
- >This will place the proper substrings into the "intoX" arrays.
-
-
-
- > -- Collins --
- >
- >-----
- >The views expressed here are mine alone.
-
- >Ron Collins/Hughes Aircraft Company/M20,P20/Tucson Az 85706
- >rcollins@thor.tu.hac.com collins@seagull.rtd.com
- >ยก----
-
-
-
-